<?php  if( !defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('to_radio'))
{
	/**
	 * to_radio
	 * 
	 * Creates markup(radio) for array. Sets checked element based on 3rd parameter.
	 * 
	 * @access public
	 * @param array
	 * @param string
	 * @param string
	 */
	function to_radio($data = array(), $name = NULL, $checked = NULL)
	{
		if (count($data) == 0) return FALSE;
		
		$ret = NULL;
		foreach ($data as $row)
		{
			$ret .= '<input type="radio" name="'. $name .'" id="'. $name .'_'. $row['value'] .'" ';
			$ret .= ($checked == $row['value']) ? 'checked="checked"' : NULL;			
			$ret .= 'value="'. $row['value'].'" />'. $row['text'] .'&nbsp;&nbsp;&nbsp;';
		}
		
		return $ret;
	}
	
	/**
	 * to_select
	 * 
	 * Creates markup(select) for array. 
	 * Sets selected element based on 3rd parameter.
	 * Creates empty option based on 4th parameter. Can contain option text
	 * 
	 * @access public
	 * @param array
	 * @param string
	 * @param string
	 * @return string
	 */
	function to_select($data = array(), $name = NULL, $selected = NULL, $empty = FALSE)
	{
		if (count($data) == 0) return FALSE;
		
		$ret = '<select name="'. $name .'" id="'. $name .'">';
		
		if ($empty)
		{
			$ret .= '<option value="">';
			$ret .= (is_string($empty)) ? $empty : '- Please select one -';
			$ret .= '</option>';
		}
		
		foreach ($data as $row)
		{
			$ret .= '<option value="'. $row['value'] .'"';
			$ret .= ($selected == $row['value']) ? 'selected="selected"' : NULL;
			$ret .= '>'. $row['text'] .'</option>';
		}
		
		return $ret .'</select>';
	}
}

/* End of file MY_file_helper.php */
/* Location: ./application/libraries/MY_file_helper.php */
